let g:asyncrun_open = 6
let g:asynctasks_extra_config = ['~/.config/obvim/tasks.ini']
let g:asynctasks_term_pos = 'tab'
let g:asynctasks_term_reuse = 1
nnoremap <M-r> <ESC>:AsyncTaskLast<CR>

if index(g:plugin_components, 'leaderf')
	function! s:lf_task_source(...)
		let rows = asynctasks#source(&columns * 48 / 100)
		let source = []
		for row in rows
			let name = row[0]
			let source += [name . '  ' . row[1] . '  : ' . row[2]]
		endfor
		return source
	endfunction

	function! s:lf_task_accept(line, arg)
		let pos = stridx(a:line, '<')
		if pos < 0
			return
		endif
		let name = strpart(a:line, 0, pos)
		let name = substitute(name, '^\s*\(.\{-}\)\s*$', '\1', '')
		if name != ''
			exec "AsyncTask " . name
		endif
	endfunction

	function! s:lf_task_digest(line, mode)
		let pos = stridx(a:line, '<')
		if pos < 0
			return [a:line, 0]
		endif
		let name = strpart(a:line, 0, pos)
		return [name, 0]
	endfunction

	function! s:lf_win_init(...)
		setlocal nonumber
		setlocal nowrap
	endfunction


	let g:Lf_Extensions = get(g:, 'Lf_Extensions', {})
	let g:Lf_Extensions.task = {
				\ 'source': string(function('s:lf_task_source'))[10:-3],
				\ 'accept': string(function('s:lf_task_accept'))[10:-3],
				\ 'get_digest': string(function('s:lf_task_digest'))[10:-3],
				\ 'highlights_def': {
				\     'Lf_hl_funcScope': '^\S\+',
				\     'Lf_hl_funcDirname': '^\S\+\s*\zs<.*>\ze\s*:',
				\ },
				\ 'help' : 'navigate available tasks from asynctasks.vim',
			\ }

	nnoremap <M-t> <ESC>:Leaderf task<CR>
elseif index(g:plugin_components, 'coc')>-1
	nnoremap <M-t> <ESC>:CocList tasks<CR>
endif
